#!/bin/sh

WAN_INTERFACE=$(echo ${INTERFACE} |grep -c wan)

if [ "$WAN_INTERFACE" -ge "1" ] && [ "$ACTION" = "ifup" ]
then
. /etc/functions.sh

ipid_ttl_get(){
 config_get ipid_pace $1 ipid_pace 0
 config_get ttl_enable $1 ttl_enable 0
 config_get ttl_set $1 ttl_set
 config_get ttl_inc $1 ttl_inc
mkdir -p /var/ipid
[ "$ipid_pace" == "1" ]&&{
sh /var/ipid/${INTERFACE}.ipid
iptables -t mangle -A POSTROUTING -o $ifname -j IPID --ipid-pace 1
echo "iptables -t mangle -D POSTROUTING -o $ifname -j IPID --ipid-pace 1" > /var/ipid/${INTERFACE}.ipid
}

[ "$ttl_enable" == "1" ]&&{
sh /var/ipid/${INTERFACE}.ttl.inc
iptables -t mangle -A PREROUTING -i $ifname -j TTL --ttl-inc $ttl_inc
echo "iptables -t mangle -D PREROUTING -i $ifname -j TTL --ttl-inc $ttl_inc" >/var/ipid/${INTERFACE}.ttl.inc
sh /var/ipid/${INTERFACE}.ttl.set
iptables -t mangle -A POSTROUTING -o $ifname -j TTL --ttl-set $ttl_set
echo "iptables -t mangle -D POSTROUTING -o $ifname -j TTL --ttl-set $ttl_set" >/var/ipid/${INTERFACE}.ttl.set
}

}
config_load ipid
INTERFACE=${INTERFACE}
ifname=$(uci get -p /var/state network.${INTERFACE}.ifname)
config_foreach ipid_ttl_get ipid_ttl
fi




